var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var mph = require("../../utils/util.js");

Page({
  data: {
    distributor_info:{
      money:'0.00'
    },//佣金账户信息
    article:'',
  },
  onLoad: function (options) {
    var that = this;
    mph.is_yue_pass()
    //获取页面数据,获取佣金账户信息
    var url = 'index.php?act=vipopen&op=distributor_info';
        mph.postRequest(url, {}, function (res) {
          // res.data.datas.flag_list/
          console.log('获取佣金账户信息:=>',res);
          if (res.data.code == 200) {
            that.setData({
              distributor_info: res.data.datas.info
            })
          }
        })
    //获取佣金规则
    var url = 'index.php?act=article&op=index&article_id=42';
    mph.postRequest(url, {type:'str'}, function (res) {
      console.log('获取佣金规则:=>',res);
      if (res.data.code == 200) {
        that.setData({
          article: res.data.datas.article_content
        })
      }
    });
  },
  /** 
   * 提取佣金为到零钱
   */
  onProfit:function(e){
    var that = this;
    var url = 'index.php?act=vipopen&op=profit_clear';
    mph.postRequest(url, {}, function (res) {
      if (res.data.code == 200) {
        setTimeout(function () {
          mph.showSuccess(res.data.datas);
        }, 1000)
        that.onLoad();
      }else{
        mph.showErrorTost(res.data.msg);
      }
    });
    
  },

  /**
 * 显示支付密码输入层
 */
  showInputLayer: function () {
    // that.onProfit()
    this.setData({ showPayPwdInput: true, payFocus: true });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function () {
    var val = this.data.pwdVal;
    this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' });
  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function (e) {
    var that = this
    this.setData({ pwdVal: e.detail.value });
    if (e.detail.value.length >= 6) {
      //执行密码验证
      var url = 'index.php?act=member_buy&op=check_password';
      mph.postRequest(url, { password: e.detail.value }, function (res) {
        if (res.data.code == 200) {
          that.hidePayLayer();
          that.onProfit()
        } else {
          mph.showErrorTost();
        }
      })
    }
  }
})
